package com.youu.youu.manager.controller;

import java.io.UnsupportedEncodingException;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.youu.youu.manager.bean.TScenicdetails;
import com.youu.youu.manager.service.ScenicdetailsService;

@Controller
@RequestMapping("/scenicdetail")
public class Scenicdetailscontroller {

	@Autowired
	ScenicdetailsService service;

	@RequestMapping("/scenicdetails")
	public String toScenicdetailsPag() {
		return "scenicdetails";
	}

	/**
	 * 获取所有景点
	 * 
	 * @param pn
	 * @param ps
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/list")
	public PageInfo<TScenicdetails> list(
			@RequestParam(value = "pn", defaultValue = "1") Integer pn,
			@RequestParam(value = "ps", defaultValue = "8") Integer ps) {
		//System.out.println("获取旅游消息");
		PageHelper.startPage(pn, ps);
		List<TScenicdetails> sceList = service.getList();
		PageInfo<TScenicdetails> pageInfo = new PageInfo<>(sceList);
		return pageInfo;
	}

	/**
	 * 删除单个景点
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/delScen", produces = "application/json; charset=utf-8")
	public String delMsg(Integer sid) {
		System.out.println("删除景点");

		boolean result = service.delete(sid);
		if (result) {
			return "{\"result\":\"删除成功！\"}";
		}
		return "{\"result\":\"删除失败！\"}";
	}

	/**
	 * 添加景点消息
	 * 
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@ResponseBody
	@RequestMapping(value = "/addScn", produces = "application/json; charset=utf-8")
	public String addScn(TScenicdetails scen) {
		// 保存到数据库中
		boolean flag = service.addScen(scen);
		if (flag) {
			return "{\"result\":\"添加成功！\"}";
		}
		return "{\"result\":\"添加失败！\"}";
	}

	/**
	 * 更新景点信息
	 * 
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@ResponseBody
	@RequestMapping(value = "/updateScn", produces = "application/json; charset=utf-8")
	public String UpdateScn(TScenicdetails scen) {
		System.out.println("调用更新方法");
		// 保存到数据库中
		System.out.println(scen);
		boolean flag = service.updateScen(scen);
		if (flag) {
			return "{\"result\":\"修改成功！\"}";
		}
		return "{\"result\":\"修改失败！\"}";
	}
	/**
	 * 按条件获取所有景点
	 * 
	 * @param pn
	 * @param ps
	 * @return
	 */
	@ResponseBody
	@RequestMapping("select")
	public PageInfo<TScenicdetails> scnList(
			@RequestParam(value = "pn", defaultValue = "1") Integer pn,
			@RequestParam(value = "ps", defaultValue = "8") Integer ps,TScenicdetails scen ) {
		//System.out.println("获取旅游消息");
		PageHelper.startPage(pn, ps);
		List<TScenicdetails> sceList = service.getScnList(scen);
		PageInfo<TScenicdetails> pageInfo = new PageInfo<>(sceList);
		return pageInfo;
	}
	
	
}
